<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑地址</title>
    <link rel="stylesheet" type="text/css" href="/secondhand/css/query.css"/>
    <script type="text/javascript" src="/secondhand/js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        $(function () {
            var params = new URLSearchParams(window.location.search);
            var addressid = params.get("addressid");
            if (addressid != null && addressid != "") {
                var url = "/secondhand/queryByAddressId.address";
                var paramObj = {
                    "addressid": addressid
                };
                $.post(url, paramObj, function (data) {
                    var jsonObj = JSON.parse(data);
                    $("#addressid").val(jsonObj.addressid);
                    $("#userfullname").val(jsonObj.userfullname);
                    $("#phone").val(jsonObj.phone);
                    $("#address").val(jsonObj.address);
                })
            }
            //校验手机号码是否符合规范
            $(":input[name='phone']").change(
                function () {
                    var phone = $(this).val();
                    var reg = /^1[3456789]\d{9}$/;
                    if (reg.test(phone)) {
                        $("#message").empty();
                        checkedSpan();
                    } else {
                        $("#message").empty().html(
                            "对不起，手机号码输入不规范");
                        $(":input[name='submit']").prop("disabled", true);
                    }
                });
            $("#submit").click(function () {
                // 检查必填项
                if ($("#phone").val().trim() == "") {
                    alert("请输入手机号码！");
                    return;
                }
                if ($("#address").val().trim() == "") {
                    alert("请输入地址！");
                    return;
                }
                if ($("#userfullname").val().trim() == "") {
                    alert("请输入收货人昵称！");
                    return;
                }
                // 提交表单
                $("form").submit();
            });
        })

        //将按钮变亮
        function checkedSpan() {
            var flag = $(".message").text();
            if (flag.length == 0) {
                $(":input[name='submit']").prop("disabled", false);
            }
        }
    </script>
</head>
<body>
<div id="top">·当前位置： 系统管理 -- 编辑地址</div>
<form action="/secondhand/updateAddress.address" method="post">
    <table id="tab" style="margin-top: 30px; border-collapse:separate; border-spacing:0px 10px;">
        <tr>
            <td align="right" style="width: 40%;">地址ID:</td>
            <td align="left"><input type="text" name="addressid" id="addressid" readonly="readonly"/></span></td>
        </tr>
        <tr>
            <td align="right" style="width: 40%;">收货人昵称:</td>
            <td align="left"><input type="text" name="userfullname" id="userfullname"/><span style="color: red"> *</span></span></td>
        </tr>
        <tr class="passwdTr">
            <td align="right" style="width: 40%;">手机号:</td>
            <td align="left"><input type="text" name="phone" id="phone"/><span style="color: red"> *</span><span
                    id="message" class="message" style="color: red"></span></td>
        </tr>
        <tr class="passwdTr">
            <td align="right" style="width: 40%;">地址:</td>
            <td align="left"><input type="text" name="address" id="address"/><span style="color: red"> *</span><span
                    id="message2" class="message" style="color: red"></span>
            </td>
        </tr>
        <tr>
            <td colspan="2"><input style="width: 60px;" type="submit" name="submit" value="提交"/></td>
        </tr>
    </table>
</form>
</body>
</html>
